package datastructure_algorithm.stack;

import java.util.Random;

public class _Test {

	public static void main(String[] args) {
//		testArrayStack();
//		testLinkedListStack();
		testCompareStack();
	}

	private static void testArrayStack() {
		ArrayStack<Integer> stack = new ArrayStack<>();
		for (int i = 0; i < 10; i++) {
			stack.push(i);
		}

		System.out.println(stack);
		stack.pop();
		System.out.println(stack);
	}

	private static void testLinkedListStack() {
		LinkedListStack<Integer> stack = new LinkedListStack<>();
		for (int i = 0; i < 10; i++) {
			stack.push(i);
		}

		System.out.println(stack);
		stack.pop();
		System.out.println(stack);
	}

	private static void testCompareStack() {
		int opCount = 10_000_000;
		ArrayStack<Integer> arrayStack = new ArrayStack<>();
		double time1 = _compareStack(arrayStack, opCount);
		System.out.println("ArrayStack:" + time1 + "s");

		LinkedListStack<Integer> linkedListStack = new LinkedListStack<>();
		double time2 = _compareStack(linkedListStack, opCount);
		System.out.println("LinkedListStack:" + time2 + "s");

	}

	private static double _compareStack(Stack<Integer> stack, int opCount) {
		long start = System.nanoTime();
		Random r = new Random();
		for (int i = 0; i < opCount; i++) {
			stack.push(r.nextInt(Integer.MAX_VALUE));
		}
		for (int i = 0; i < opCount; i++) {
			stack.pop();
		}
		long end = System.nanoTime();
		return (end - start) / 1_000_000_000.0;

	}

}
